library(tidyverse)
library(cowplot)
library(broom)
library(pwr)
library(plotly)
#setwd("~/GitHub/time-course/data")
setwd("~/Library/Mobile\ Documents/com~apple~CloudDocs/time-course/data")
rawdata <- "revised_MASTER-ExperimentSummary.csv"
timecourse <- "timecourse2017.csv"
data <- read_csv(rawdata)
tc <- read_csv(timecourse, na = c("","NA"))
data1 <- data %>%
gather(Sample,Count,2:250)
# Separate samples by identifiers
data2 <- data1 %>%
separate(Sample, into=c("Sample_ID","Dilution_factor","Injection","Tech_rep", sep = "_")) %>%
select(-`_`)
# Refactoring Columns for samples
data2$Sample_ID <- as.factor(data2$Sample_ID)
data2$Dilution_factor <- as.numeric(data2$Dilution_factor)
data2$Injection<- as.factor(data2$Injection)
data2$Tech_rep <- as.numeric(data2$Tech_rep)
# Refactoring COlumns for timecourse
tc$Sample_ID <- as.factor(tc$Sample_ID)
tc$Day <- as.factor(tc$Day)
tc$Weight <- as.numeric(tc$Weight)
tc$TEI_Day <- as.factor(tc$TEI_Day)
tc1 <- tc %>%
select(Day:Pups)
tc1
data2 <- data2 %>%
mutate(True_Count=Dilution_factor*Count)
data2
data3 <- data2 %>%
group_by(particle_size,Sample_ID,Dilution_factor,Injection) %>%
summarise( tech_N = length(True_Count),
tech_mean = mean(True_Count),
tech_sd = sd(True_Count),
tech_se = tech_sd/sqrt(tech_N))
data3
test1 <- left_join(tc1,data3, by= "Sample_ID")
data4 <- data3 %>%
group_by(particle_size,Sample_ID,Dilution_factor) %>%
summarise( inj_N = length(tech_mean),
inj_mean = mean(tech_mean),
inj_sd = sd(tech_mean),
inj_se = inj_sd/sqrt(inj_N))
data4
test2 <- left_join(tc1,data4, by= "Sample_ID")
test2
test1$Sample_ID_correct = factor(test1$Sample_ID, levels=c('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','70','73','74','75'))
graph1 <- test1 %>%
ggplot(aes(x=particle_size, y=tech_mean,color=Injection ))+ #plot
geom_ribbon(aes(ymin=tech_mean-tech_se,
ymax=tech_mean+tech_se),
alpha=0.2,fill = alpha('grey12', 0.2)) + #error bars
geom_line(size=2.0) + xlim(0,500)+ #line size, x-axis scale
scale_y_continuous(expand=c(0,0))+ #set bottom of graph
xlab("Particle Size") + # X axis label
ylab("\nMean Particle Concentration/ml\n") + # Y axis label
ggtitle("Nanosight Histogram of\nVirgin Mouse Plasma")+ #title
labs(color="Injection")+ #Label table title
facet_wrap( ~ Sample_ID_correct, nrow=7)
graph1
Virgin Mice
test1 %>%
filter(Day == '1') %>%
ggplot(aes(x=particle_size, y=tech_mean,color=Injection ))+ #plot
geom_ribbon(aes(ymin=tech_mean-tech_se,
ymax=tech_mean+tech_se),
alpha=0.2,fill = alpha('grey12', 0.2)) + #error bars
geom_line(size=1.0) + xlim(0,500)+ #line size, x-axis scale
scale_y_continuous(expand=c(0,0))+ #set bottom of graph
xlab("Particle Size") + # X axis label
ylab("\nMean Particle Concentration/ml\n") + # Y axis label
ggtitle("Nanosight Histogram of\nVirgin Mouse Plasma")+ #title
labs(color="Injection")+ #Label table title
facet_wrap( ~ Sample_ID_correct)+
geom_vline(xintercept = 140)+
annotate("text", x= 235, y = 4E9, label= "140nm")
GD 5.5
test1 %>%
filter(Day == '5') %>%
ggplot(aes(x=particle_size, y=tech_mean,color=Injection ))+ #plot
geom_ribbon(aes(ymin=tech_mean-tech_se,
ymax=tech_mean+tech_se),
alpha=0.2,fill = alpha('grey12', 0.2)) + #error bars
geom_line(size=1.0) + xlim(0,500)+ #line size, x-axis scale
scale_y_continuous(expand=c(0,0))+ #set bottom of graph
xlab("Particle Size") + # X axis label
ylab("\nMean Particle Concentration/ml\n") + # Y axis label
ggtitle("Nanosight Histogram of\nVirgin Mouse Plasma")+ #title
labs(color="Injection")+ #Label table title
facet_wrap( ~ Sample_ID_correct)+
geom_vline(xintercept = 140)+
annotate("text", x= 235, y = 4E9, label= "140nm")
GD 10.5
test1 %>%
filter(Day == '10') %>%
ggplot(aes(x=particle_size, y=tech_mean,color=Injection ))+ #plot
geom_ribbon(aes(ymin=tech_mean-tech_se,
ymax=tech_mean+tech_se),
alpha=0.2,fill = alpha('grey12', 0.2)) + #error bars
geom_line(size=1.0) + xlim(0,500)+ #line size, x-axis scale
scale_y_continuous(expand=c(0,0))+ #set bottom of graph
xlab("Particle Size") + # X axis label
ylab("\nMean Particle Concentration/ml\n") + # Y axis label
ggtitle("Nanosight Histogram of\nVirgin Mouse Plasma")+ #title
labs(color="Injection")+ #Label table title
facet_wrap( ~ Sample_ID_correct)+
geom_vline(xintercept = 140)+
annotate("text", x= 235, y = 4E9, label= "140nm")
GD 14.5
test1 %>%
filter(Day == '14') %>%
ggplot(aes(x=particle_size, y=tech_mean,color=Injection ))+ #plot
geom_ribbon(aes(ymin=tech_mean-tech_se,
ymax=tech_mean+tech_se),
alpha=0.2,fill = alpha('grey12', 0.2)) + #error bars
geom_line(size=1.0) + xlim(0,500)+ #line size, x-axis scale
scale_y_continuous(expand=c(0,0))+ #set bottom of graph
xlab("Particle Size") + # X axis label
ylab("\nMean Particle Concentration/ml\n") + # Y axis label
ggtitle("Nanosight Histogram of\nVirgin Mouse Plasma")+ #title
labs(color="Injection")+ #Label table title
facet_wrap( ~ Sample_ID_correct)+
geom_vline(xintercept = 140)+
annotate("text", x= 235, y = 4E9, label= "140nm")
GD 17.5
test1 %>%
filter(Day == '17') %>%
ggplot(aes(x=particle_size, y=tech_mean,color=Injection ))+ #plot
geom_ribbon(aes(ymin=tech_mean-tech_se,
ymax=tech_mean+tech_se),
alpha=0.2,fill = alpha('grey12', 0.2)) + #error bars
geom_line(size=1.0) + xlim(0,500)+ #line size, x-axis scale
scale_y_continuous(expand=c(0,0))+ #set bottom of graph
xlab("Particle Size") + # X axis label
ylab("\nMean Particle Concentration/ml\n") + # Y axis label
ggtitle("Nanosight Histogram of\nVirgin Mouse Plasma")+ #title
labs(color="Injection")+ #Label table title
facet_wrap( ~ Sample_ID_correct)+
geom_vline(xintercept = 140)+
annotate("text", x= 235, y = 4E9, label= "140nm")
1 Day Post
test1 %>%
filter(Day == '20') %>%
ggplot(aes(x=particle_size, y=tech_mean,color=Injection ))+ #plot
geom_ribbon(aes(ymin=tech_mean-tech_se,
ymax=tech_mean+tech_se),
alpha=0.2,fill = alpha('grey12', 0.2)) + #error bars
geom_line(size=1.0) + xlim(0,500)+ #line size, x-axis scale
scale_y_continuous(expand=c(0,0))+ #set bottom of graph
xlab("Particle Size") + # X axis label
ylab("\nMean Particle Concentration/ml\n") + # Y axis label
ggtitle("Nanosight Histogram of\nVirgin Mouse Plasma")+ #title
labs(color="Injection")+ #Label table title
facet_wrap( ~ Sample_ID_correct)+
geom_vline(xintercept = 140)+
annotate("text", x= 235, y = 4E9, label= "140nm")
graph2 <- test2 %>%
group_by(TEI_Day) %>%
ggplot(aes(x=particle_size, y=inj_mean,color=Day ))+ #plot
#geom_ribbon(aes(ymin=inj_mean-inj_se, ymax=inj_mean+inj_se),alpha=0.2,fill = alpha('grey12', 0.2)) + #error bars
geom_line(size=2) + xlim(0,500)+ #line size, x-axis scale
scale_y_continuous(expand=c(0,0))+ #set bottom of graph
xlab("Particle Size") + # X axis label
ylab("\nMean Particle Concentration/ml\n") + # Y axis label
ggtitle("Nanosight Histogram of\nVirgin Mouse Plasma")+ #title
labs(color="Condition")+ #Label table title
facet_wrap(~ TEI_Day, ncol=7)
graph2
test3 <- test2 %>%
group_by(Day,Sample_ID) %>%
summarise(particle_conc=sum(inj_mean))
test3
test4 <- test3 %>%
group_by(Day) %>%
summarise(Day_N=length(particle_conc),
Day_mean = mean(particle_conc),
Day_sd = sd(particle_conc),
Day_se = Day_sd/sqrt(Day_N))
test4
plot1 <- test3 %>%
filter(!Sample_ID %in% c('6','28','32')) %>%
group_by(Day) %>%
ggplot(aes(x= Day, y = particle_conc, color=Day)) +
geom_boxplot(colour="black",fill=NA) +
geom_point(aes(text = paste("Sample ID:", Sample_ID)),
position='jitter',size=3)+
xlab("\nDay of Gestation\n") + # X axis label
ylab("\nExosomes/ml\n") + # Y axis label
ggtitle("Plasma Exosome Concentration\nThroughout Pregnancy\n")+ #title
labs(color="Condition")+ # Label table title
scale_x_discrete(breaks=c("1","5","10","14","17","20"), # Change X axis label
labels=c("Virgin","5","10","14","17","1 Day Post")) +
scale_color_discrete(labels=c("Virgin","5","10","14","17","1 Day Post")) # Change Legend
plot1
#ggsave("Exosome_plot.png", height = 5, width = 7, units = "in", dpi = 600)
ggplotly(plot1)
plot <- test4 %>%
ggplot(aes(x=Day, y=Day_mean, fill=Day ))+ #plot
geom_col()+
geom_errorbar(aes(ymin=Day_mean-Day_se, ymax=Day_mean+Day_se), width=.5,
size=0.8, colour="black", position=position_dodge(.9)) + #error bars
scale_y_continuous(expand=c(0,0), breaks = seq(1E11,4E11,1E11))+ #set bottom of graph and scale
xlab("\nDay of Gestation\n") + # X axis label
ylab("\nExosomes/ml\n") + # Y axis label
ggtitle("Plasma Exosome Concentration\nThroughout Pregnancy\n")+ #title
labs(fill="Condition") + # Label table title
scale_x_discrete(breaks=c("1","5","10","14","17","20"), # Change X axis label
labels=c("Virgin","5","10","14","17","1 Day Post")) +
scale_fill_discrete(labels=c("Virgin","5","10","14","17","1 Day Post"))
plot
ggsave("Exosome_barplot.png", height = 5, width = 7, units = "in", dpi = 600)
test7 <- test3 %>%
left_join(tc1)
Joining, by = c("Day", "Sample_ID")
plot2 <- test7 %>%
ggplot(aes(x = Day, y = particle_conc, color = Day, shape=TEI_Day))+
geom_point(position= 'dodge',size=4)+
scale_shape_manual(values=c(15,16,17,18,22,23,24))+
xlab("\nDay of Gestation\n") + # X axis label
ylab("\nExosomes/ml\n") + # Y axis label
ggtitle("Plasma Exosome Concentration\nThroughout Pregnancy\n")+ #title
labs(color="Condition") + # Label table title
scale_x_discrete(breaks=c("1","5","10","14","17","20"), # Change X axis label
labels=c("Virgin","5","10","14","17","1 Day Post")) +
scale_color_discrete(labels=c("Virgin","5","10","14","17","1 Day Post"))
plot2
ggplotly(plot2)
Width not defined. Set with `position_dodge(width = ?)`
nano_100 <- data4 %>%
filter(particle_size<140.5)
nano_100_data <- left_join(tc1,nano_100, by= "Sample_ID")
nano_100_data_plot <- nano_100_data %>%
group_by(Day,Sample_ID) %>%
summarise(particle_conc=sum(inj_mean)) %>%
filter(!Sample_ID %in% c('6','28','32')) %>%
ggplot(aes(factor(Day),particle_conc, color=Day)) +
geom_boxplot(colour="black",fill=NA) +
geom_point(position='jitter',size=3)+
xlab("\nDay of Gestation\n") + # X axis label
ylab("\nExosomes/ml\n") + # Y axis label
ggtitle("Plasma Exosome Concentration\nThroughout Pregnancy\n")+ #title
labs(color="Condition") + # Label table title
scale_x_discrete(breaks=c("1","5","10","14","17","20"), # Change X axis label
labels=c("Virgin","5","10","14","17","1 Day Post")) +
scale_color_discrete(labels=c("Virgin","5","10","14","17","1 Day Post"))
nano_100_data_plot
NA
tidy(shapiro.test(test3$particle_conc))
p value >0.05 therefore conclude data is normally distributed
jacob <- nano_100_data %>%
group_by(Day,Sample_ID) %>%
summarise(particle_conc=sum(inj_mean)) %>%
filter(!Sample_ID %in% c('6','28','32'))
fit <- aov(particle_conc ~ Day, data=jacob)
stats <- tidy(fit)
stats
Statistically significant, thus Tukey’s HSD post hoc analysis can determine significant differences.
HSD <- TukeyHSD(fit)
tukey <- tidy(HSD)
tukey
tukey %>%
filter(adj.p.value<0.05) %>%
arrange(adj.p.value)
test8 <- test7 %>%
filter(!Day == "20")
fit <- lm(particle_conc ~ Weight ,data = test8)
summary(fit)
Call:
lm(formula = particle_conc ~ Weight, data = test8)
Residuals:
Min 1Q Median 3Q Max
-2.600e+11 -7.122e+10 -2.456e+10 8.690e+10 2.239e+11
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.768e+10 7.666e+10 0.752 0.45727
Weight 8.548e+09 2.849e+09 3.000 0.00519 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1.127e+11 on 32 degrees of freedom
Multiple R-squared: 0.2196, Adjusted R-squared: 0.1952
F-statistic: 9.002 on 1 and 32 DF, p-value: 0.00519
tidy(summary(fit))
test7 %>%
ggplot(aes(x= Weight, y = particle_conc))+
geom_point()+
geom_smooth()+
xlab("\nWeight (g)\n") + # X axis label
ylab("Exosomes/ml\n") + # Y axis label
ggtitle("Linear Regression of Exosome \nConcentration vs. Weight")+ #title
labs(color="Day")#Label table title
NA
test7 %>%
filter(!Sample_ID == '70') %>%
ggplot(aes(x= Weight, y = particle_conc))+
geom_point(size = 3,aes(color=factor(Day)))+
geom_smooth(method = "lm", level = 0.95)+
xlab("\nWeight (g)\n") + # X axis label
ylab("Exosomes/ml\n") + # Y axis label
ggtitle("Linear Regression of Exosome \nConcentration vs. Weight")+ #title
labs(color="Day")#Label table title
test7 %>%
ggplot(aes(x= Pups, y = particle_conc))+
geom_point(size = 4, aes(color=factor(Day)))+
#geom_smooth(method = "lm", level = 0.95)+
scale_x_continuous(breaks=seq(0,12,2))+
xlab("\nNumbwe of Pups\n") + # X axis label
ylab("Exosomes/ml\n") + # Y axis label
ggtitle("Linear Regression of Exosome \nConcentration vs. Number of Pups")+ #title
labs(color="Day")#Label table title
mean_placenta <- tc %>%
filter(Day %in% c('10','14','17') & !Sample_ID %in% c('70','73','74','75')) %>%
select(-(TEI_Day:Pup_right),-Resorp) %>%
gather("Placenta_avg","Plac_weight", 3:5) %>%
group_by(Day,Sample_ID) %>%
summarise(N = length(Plac_weight),
mean_plac = mean(Plac_weight*1000, na.rm = TRUE), #convert g to mg
sd = sd(Plac_weight)*1000, #convert g to mg
se = sd/sqrt(N))
mean_placenta %>%
inner_join(test7) %>%
ggplot(aes(x= mean_plac, y = particle_conc))+
geom_point(size= 3,aes(color=factor(Day)))+
geom_smooth(method = "lm", level = 0.95)+
xlab("\nPlacental Weight (mg)\n") + # X axis label
ylab("\nExosomes/ml\n") + # Y axis label
ggtitle("Plasma Exosome Concentration\nThroughout Pregnancy\n")+ #title
labs(color="G.D.")#Label table title
Joining, by = c("Day", "Sample_ID")
joining factor and character vector, coercing into character vector
mean_placenta %>%
inner_join(test7) %>%
ggplot(aes(x = Pups, y = particle_conc))+
geom_point(size= 3,aes(color=factor(Day)))+
geom_smooth(method = "lm", se= FALSE)+
facet_wrap(~Day)+
scale_x_continuous(breaks=seq(1,12,2))+
xlab("\nNumbr of Pups\n") + # X axis label
ylab("\nExosomes/ml\n") + # Y axis label
ggtitle("Plasma Exosome Concentration\nThroughout Pregnancy\n")+ #title
labs(color="G.D.")#Label table title
Joining, by = c("Day", "Sample_ID")
joining factor and character vector, coercing into character vector
test3 %>%
filter(!Day %in% c('1','20')) %>%
group_by(Day) %>%
ggplot(aes(factor(Day),particle_conc, color=Day)) +
geom_point(size=3)+
xlab("\nDay of Gestation\n") + # X axis label
ylab("\nExosomes/ml\n") + # Y axis label
ggtitle("Plasma Exosome Concentration\nThroughout Pregnancy\n")+ #title
labs(color="Condition")#Label table title
nanosight_plot <- test1 %>%
filter(Sample_ID == '75') %>%
ggplot(aes(x=particle_size, y=tech_mean,color=Injection ))+ #plot
geom_ribbon(aes(ymin=tech_mean-tech_se, ymax=tech_mean+tech_se),alpha=0.2,fill = alpha('grey12', 0.2)) + #error bars
geom_line(size=1.0) + xlim(0,500)+ #line size, x-axis scale
scale_y_continuous(expand=c(0,0))+ #set bottom of graph
xlab("Particle Size (nm)") + # X axis label
ylab("\nMean Particle Concentration/ml\n") + # Y axis label
ggtitle("Nanosight Histogram of\nVirgin Mouse Plasma")+ #title
labs(color="Injection")+ #Label table title
facet_wrap( ~Injection)
nanosight_plot
ggsave("Nanosight_plot.png", height = 5, width = 7, units = "in", dpi = 600)
test3 %>%
filter(!Sample_ID %in% c('1','6','15','16','19','24','29','6','28','32')) %>%
group_by(Day) %>%
ggplot(aes(x= Day, y = particle_conc, color=Day)) +
geom_boxplot(colour="black",fill=NA) +
geom_point(aes(text = paste("Sample ID:", Sample_ID)),
position='jitter',size=3)+
xlab("\nDay of Gestation\n") + # X axis label
ylab("\nExosomes/ml\n") + # Y axis label
ggtitle("Plasma Exosome Concentration\nThroughout Pregnancy\n")+ #title
labs(color="Condition")+ # Label table title
scale_x_discrete(breaks=c("1","5","10","14","17","20"), # Change X axis label
labels=c("Virgin","5","10","14","17","1 Day Post")) +
scale_color_discrete(labels=c("Virgin","5","10","14","17","1 Day Post")) # Change Legend
Ignoring unknown aesthetics: text
filtered_data <- test3 %>%
filter(!Sample_ID %in% c('1','6','15','16','19','24','29','6','28','32'))
filtered_fit <- aov(particle_conc ~ Day, data=filtered_data)
filtered_stats <- tidy(filtered_fit)
filtered_stats
filtered_HSD <- TukeyHSD(filtered_fit)
filtered_tukey <- tidy(filtered_HSD)
filtered_tukey %>%
filter(adj.p.value < 0.05) %>%
arrange(adj.p.value)